package liurong.driver.concurrent;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * CyclicBarrier的作用：等设置的线程屏障值==await()的线程数时，程序才会往下执行
 * 
 * @author liurong
 *
 */
public class CyclicBarrierTest1 {
	public static CyclicBarrier cyclicBarrier = new CyclicBarrier(6);

	public static void main(String[] args) throws Exception {
		for (int i = 0; i < 5; i++) {
			Thread thread = new Thread(new Runnable() {
				public void run() {
					try {
						cyclicBarrier.await();
					} catch (InterruptedException e) {
						e.printStackTrace();
					} catch (BrokenBarrierException e) {
						e.printStackTrace();
					}
					System.out.println("run");
				}
			});

			thread.start();
		}
		cyclicBarrier.await();
		System.out.println("game over!");

	}
}
